package com.cwt.admin.system;

import cn.dev33.satoken.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cwt.admin.common.BaseController;
import com.cwt.common.result.AjaxResult;
import com.cwt.common.utils.SqlUtils;
import com.cwt.common.vo.PageInfo;
import com.cwt.service.domain.TbBook;
import com.cwt.service.service.TbBookService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenwt
 * @version V1.0
 * @describe 【图书管理】
 * @date 2023年07月26日 11:14:11
 */
@Api(tags = "图书管理", value = "BookController")
@RequestMapping("/book")
@RestController
public class BookController extends BaseController {

    @Autowired
    private TbBookService tbBookService;

    /**
     * 图书分页查询
     *
     * @param info 分页查询条件
     * @return 图书分页数据信息
     */
    @RequestMapping(value = "/page", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    AjaxResult page(@RequestBody PageInfo info) {
        Page<TbBook> page = new Page<>(info.getPageNum(), info.getPageSize());
        QueryWrapper<TbBook> queryWrapper = new QueryWrapper<>();
        SqlUtils.wrapperSetLikeCondition(queryWrapper, info.getParams());
        page = tbBookService.page(page, queryWrapper);
        return AjaxResult.success(page);
    }

    /**
     * 图书分页查询
     *
     * @param info 分页查询条件
     * @return 图书分页数据信息
     */
    @RequestMapping(value = "/hotPage", method = {RequestMethod.POST, RequestMethod.GET})
    public @ResponseBody
    AjaxResult hotPage(@RequestBody PageInfo info) {
        Page<TbBook> page = new Page<>(info.getPageNum(), info.getPageSize());
        QueryWrapper<TbBook> queryWrapper = new QueryWrapper<>();
        SqlUtils.wrapperSetLikeCondition(queryWrapper, info.getParams());
        return AjaxResult.success(tbBookService.page(page, queryWrapper));
    }

}
